<template>
	<view class="demo-block">
		<text class="demo-block__title-text ultra">图标</text>
		<text class="demo-block__desc-text">小标题</text>
		<view class="demo-block__body">
			<view class="demo-block card">
				<text class="demo-block__title-text large">内置ICON</text>
				<text class="demo-block__title-text">内置 tdesign icon font </text>
				<view class="demo-block__body">

					<!-- 内置 ICON -->
					<view style="height: 500rpx;">
						<scroll-view style="height: 500rpx;" v-if="iconsData.length > 0" scroll-y>
							<!-- #ifdef VUE3 -->
							<template v-for="(group) in iconsData" :key="group" :type="group">
								<view class="grid" >
									<view class="grid-item" v-for="item in group" :key="item">
										<l-icon :key="item" :name="item" @click="onClick(item)"></l-icon>
										<text class="grid-item-text">{{item}}</text>
									</view>
								</view>
							</template>
							<!-- #endif -->
							<!-- #ifndef VUE3 -->
							<block v-for="(group) in iconsData" :key="group" :type="group">
								<view class="grid" >
									<view class="grid-item" v-for="item in group" :key="item">
										<l-icon :key="item" :name="item" @click="onClick(item)"></l-icon>
										<text class="grid-item-text">{{item}}</text>
									</view>
								</view>
							</block>
							<!-- #endif -->
						</scroll-view>
					</view>
				</view>
			</view>

			<view class="demo-block card">
				<text class="demo-block__title-text large">使用图片</text>
				<view class="demo-block__body">
					<!-- 使用图片 -->
					<view class="grid">
						<view class="grid-item" v-for="item in imageList" :key="item">
							<l-icon :key="item" :name="item" @click="onClick(item)"></l-icon>
						</view>
					</view>
				</view>
			</view>

			<view class="demo-block card">
				<text class="demo-block__title-text large">iconify</text>
				<view class="demo-block__body">
					<!-- iconify -->
					<view class="grid">
						<view class="grid-item">
							<l-icon name="uil:12-plus" color="blue" @click="onClick('uil:12-plus')"></l-icon>
						</view>
						<view class="grid-item">
							<l-icon name="icon-park-outline:abdominal"></l-icon>
						</view>
						<view class="grid-item">
							<l-icon name="icon-park-outline:acoustic"></l-icon>
						</view>
						<view class="grid-item">
							<l-icon name="ph:tabs-bold"></l-icon>
						</view>
						<view class="grid-item">
							<l-icon name="ri:aliens-fill" size="100px"></l-icon>
						</view>
						
					</view>

				</view>
			</view>
		</view>
	</view>
</template>
<script>
	// @ts-nocheck
	// import { icons } from '../l-icon/icons'
	import { icons } from './icons.ts'
	// import { iconsArr } from './icons'
	// import icons from '../../static/icons.json';
	// type T = {}
	export default {
		data() {
			return {
				show: false,
				page: 0,
				pageSize: 8,
				iconsData: [] ,
				icons: [],
				customList: [
					'add-circle',
					// 'image-fill',
					// 'image-fail-fill',
					// 'close-circle-fill',
					// 'close',
				],
				imageList: [
					'https://fastly.jsdelivr.net/npm/@vant/assets/icon-demo.png',
					""
				],
				color: 'blue'
			}
		},
		created() {
			let group = []
			let groups = []
			// let index = 0
			// console.log('icons', icons)
			Object.keys(icons).forEach((key,index) => {
				if (index % 3 == 0) {
					group = []
					group.push(key)
				} else if (index % 3 == 2) {
					group.push(key)
					groups.push(group)
				} else {
					group.push(key)
				}
			})

			this.icons = groups
			this.loadData()
		},
		methods: {
			loadData() {

				const end = this.page + this.pageSize
				this.iconsData = this.icons.slice(this.page, end)
				this.page = end
			},
			onShow() {
				this.show = !this.show
			},
			onClick(name) {
				console.log('click')
				uni.setClipboardData({
					data: name,
					success: function () {
						uni.showToast({
							title: name
						})
					}
				})
				console.log('icon name:', name)
			}
		},
		mounted() {
			setTimeout(() => {
				this.color = 'red'
			}, 1000)
		}
	}
</script>
<style lang="scss">
	.alt {
		// background-color: aqua;
		color: blue
	}

	.grid {
		display: flex;
		// flex: 1;
		flex-direction: row;
		flex-wrap: wrap;

		&-item {
			display: flex;
			flex-direction: column;
			flex-basis: 33.33%;
			align-items: center;
			padding-bottom: 20rpx;

			&-text {
				padding-top: 10rpx;
				font-size: 22rpx;
				opacity: 0.6;
			}
		}
	}



	.demo-block {
		padding: 32px 10px 0;
		width: 100%;
		box-sizing: border-box;
		overflow: visible;

		&.card {
			padding: 20rpx 20rpx;
			background-color: white;
			margin-bottom: 20rpx;
		}

		&__title {
			margin: 0;
			margin-top: 8px;

			&-text {
				color: rgba(0, 0, 0, 0.6);
				font-weight: 400;
				font-size: 14px;
				line-height: 16px;
				display: block;
				&.large {
					color: rgba(0, 0, 0, 0.9);
					font-size: 18px;
					font-weight: 700;
					line-height: 26px;
				}

				&.ultra {
					color: rgba(0, 0, 0, 0.9);
					font-size: 24px;
					font-weight: 700;
					line-height: 32px;
				}
			}
		}

		&__desc-text {
			color: rgba(0, 0, 0, 0.6);
			margin: 8px 16px 0 0;
			font-size: 14px;
			line-height: 22px;
		}

		&__body {
			margin: 16px 0;
			overflow: visible;

			.demo-block {
				margin: 0;
			}
		}
	}
</style>